package cn.wanda.bi.sunshine.platform.server.context;

/**
 * Created by wangfupeng1 on 2017-4-8.
 */
public class ContextHolder {

    private static final ThreadLocal<Context> holder = new ThreadLocal<>();

    public static Context getContext() {
        Context context = holder.get();
        if (context == null) {
            context = new Context();
            holder.set(context);
        }
        return context;
    }

    public static void setContext(Context context) {
        holder.set(context);
    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        if (holder != null) {
            holder.remove();
        }
    }
}
